/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
using IQName = System.Qizx.Xdm.IQName;
namespace System.Qizx.Api {


    /// <summary> Exception thrown by an error in the execution of an XQuery Expression.</summary>
    [Serializable]
    public class EvaluationException : QizxException {
        /// <summary> Returns the execution stack at the moment of the error.
        /// <p>
        /// </summary>
        /// <returns> an array of EvaluationStackTrace objects. The first array
        /// element corresponds to the innermost execution level. The last
        /// element corresponds to the main query.
        /// </returns>
        /// <summary> For internal use.</summary>
        virtual public EvaluationStackTrace[] Stack {
            get {
                return stack;
            }

            set {
                this.stack = value;
            }

        }
        /// <summary>Error code used when the time limit for evaluation has been reached. </summary>
        public static readonly QName TIME_LIMIT;
        /// <summary>Error code used when the evaluation has been explicitly cancelled. </summary>
        public static readonly QName CANCELLED;

        protected internal static readonly QName DEFAULT_ERR_CODE;

        private static readonly EvaluationStackTrace[] NO_STACK = new EvaluationStackTrace[0];

        private EvaluationStackTrace[] stack;

        /// <summary> Constructs an EvaluationException from a simple message.
        /// The error code is undefined.
        /// </summary>
        public EvaluationException(string message)
            : base(DEFAULT_ERR_CODE, message) {
            stack = NO_STACK;
        }

        /// <summary> Constructs an EvaluationException from a simple message and an error code.</summary>
        public EvaluationException(QName xqueryCode, string message)
            : base(xqueryCode, message) {
            stack = NO_STACK;
        }

        /// <summary> Constructs an EvaluationException from a simple message and an exception.
        /// The error code is undefined.
        /// </summary>
        public EvaluationException(string message, System.Exception cause)
            : base(message, cause) {
            setErrorCode(DEFAULT_ERR_CODE);
            stack = NO_STACK;
        }

        /// <summary> Constructs an EvaluationException from a simple message, an error code
        /// and an exception.
        /// </summary>
        public EvaluationException(QName xqueryCode, string message, System.Exception cause)
            : base(message, cause) {
            setErrorCode(xqueryCode);
            stack = NO_STACK;
        }
        static EvaluationException() {
            TIME_LIMIT = IQName.GetQName("TIME_LIMIT");
            CANCELLED = IQName.GetQName("CANCELLED");
            DEFAULT_ERR_CODE = IQName.GetQName("XQST0054");
        }
    }
}